package com.gitee.chessboard.jdbc.executor;

import com.gitee.chessboard.enums.OrmType;
import com.gitee.chessboard.jdbc.JdbcManager;
import com.gitee.chessboard.jdbc.executor.mybatis.MybatisSqlExecutor;

/**
 * 执行器的简单工厂
 *
 * @author 敲代码的旺财
 * @date 2021/11/18 14:20
 */
public class SqlExecutorFactory {

    private OrmType ormType;

    /**
     * jdbc的管理器
     */
    private JdbcManager jdbcManager;

    public SqlExecutorFactory(JdbcManager jdbcManager) {
        this.jdbcManager = jdbcManager;
        try {
            Class.forName("org.apache.ibatis.session.SqlSessionFactory");
            this.ormType = OrmType.MYBATIS;
            return;


        } catch (ClassNotFoundException e) {
            throw new RuntimeException("无法识别orm", e);
        }
    }

    /**
     * 获取执行器
     *
     * @return 执行器
     */
    public SqlExecutor get() {
        if (ormType.equals(OrmType.MYBATIS)) {
            return new MybatisSqlExecutor(jdbcManager);
        }
        return null;
    }
}
